package visiopuce.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.nebula.widgets.formattedtext.DateFormatter;
import org.eclipse.nebula.widgets.formattedtext.FormattedText;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

import visiopuce.ApplicationContexte;
import visiopuce.objets.FeuillePuce;
import visiopuce.objets.TypePrelevement;
import visiopuce.ui.listener.GenererCultureListener;
import visiopuce.ui.view.PrelevementTabItem;

public class QuelTravailDialog extends Dialog {

	private Combo comboTravail;

	String titre;
	private Button btnPrnatal;
	private Button btnPucesPre;
	private Button btnPostnatal;
	private Button btnPucesPost;
	private Button btnFoeto;
	private Button btnPucesFoeto;
	private Button btnCaryo;
	private Button btnFishPuce;
	private Button btnFishNonPuce;
	private Button btnBM;
	private Button btnPuce;
	private Button btnMicroSat;
	private SelectionAdapter selectionSecteurListener;
	private Composite container;

	private String travail;

	private String analyse;

	public QuelTravailDialog(Shell parentShell) {
		super(parentShell);
		setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
		setBlockOnOpen(true);
	}

	@Override
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText("Choix de la liste de travail");
		selectionSecteurListener = new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				String[] liste = null;
				if (btnPrnatal.getSelection() || btnPostnatal.getSelection() || btnFoeto.getSelection() || btnCaryo.getSelection()) {
					liste = new String[] { "A choquer", "A étaler", "A dénaturer", "A lire", "A relire", "Résultat à rédiger", "A signer" };
				}

				if (btnPucesPre.getSelection() || btnPucesPost.getSelection() || btnPucesFoeto.getSelection() || btnPuce.getSelection()) {
					liste = new String[] { "A techniquer", "A lire", "A relire", "A passer en réunion", "Résultat à rédiger", "A signer" };
				}

				if (btnFishPuce.getSelection() || btnFishNonPuce.getSelection() || btnMicroSat.getSelection()) {
					liste = new String[] { "A techniquer", "Résultat à rédiger", "A signer" };
				}
				if (btnBM.getSelection()) {
					liste = new String[] { "A techniquer", "Résultat à rédiger", "A relire", "A signer" };
				}
				comboTravail.setItems(liste);
				container.pack();
			}
		};
	}

	@Override
	protected Control createDialogArea(Composite parent) {

		container = (Composite) super.createDialogArea(parent);
		GridLayout layout = new GridLayout(1, false);
		layout.marginRight = 5;
		layout.marginLeft = 10;
		container.setLayout(layout);

		Label lblParSecteur = new Label(container, SWT.NONE);
		lblParSecteur.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		lblParSecteur.setText("Analyse par secteur");
		new Label(container, SWT.NONE);

		Group group = new Group(container, SWT.NONE);
		group.setLayout(new GridLayout(3, false));

		btnPuce = new Button(group, SWT.RADIO);
		btnPuce.setText("Puce tout secteur");
		btnPuce.addSelectionListener(selectionSecteurListener);

		btnPucesPre = new Button(group, SWT.RADIO);
		btnPucesPre.setText(ApplicationContexte.SECTEUR_PUCE_PRENATAL);
		btnPucesPre.addSelectionListener(selectionSecteurListener);

		btnPucesPost = new Button(group, SWT.RADIO);
		btnPucesPost.setText(ApplicationContexte.SECTEUR_PUCE_POSTNATAL);
		btnPucesPost.addSelectionListener(selectionSecteurListener);

		btnPucesFoeto = new Button(group, SWT.RADIO);
		btnPucesFoeto.setText(ApplicationContexte.SECTEUR_PUCE_FOETO);
		btnPucesFoeto.addSelectionListener(selectionSecteurListener);

		btnCaryo = new Button(group, SWT.RADIO);
		btnCaryo.setText("Caryotype tout secteur");
		btnCaryo.addSelectionListener(selectionSecteurListener);

		btnPrnatal = new Button(group, SWT.RADIO);
		btnPrnatal.setText("Caryotype " + ApplicationContexte.SECTEUR_PRENATAL);
		btnPrnatal.addSelectionListener(selectionSecteurListener);

		btnPostnatal = new Button(group, SWT.RADIO);
		btnPostnatal.setText("Caryotype " + ApplicationContexte.SECTEUR_POSTNATAL);
		btnPostnatal.addSelectionListener(selectionSecteurListener);

		btnFoeto = new Button(group, SWT.RADIO);
		btnFoeto.setText("Caryotype " + ApplicationContexte.SECTEUR_FOETO);
		btnFoeto.addSelectionListener(selectionSecteurListener);

		btnFishPuce = new Button(group, SWT.RADIO);
		btnFishPuce.setText("FISH puce");
		btnFishPuce.addSelectionListener(selectionSecteurListener);

		btnFishNonPuce = new Button(group, SWT.RADIO);
		btnFishNonPuce.setText("FISH non puce");
		btnFishNonPuce.addSelectionListener(selectionSecteurListener);

		btnBM = new Button(group, SWT.RADIO);
		btnBM.setText("qPCR");
		btnBM.addSelectionListener(selectionSecteurListener);

		btnMicroSat = new Button(group, SWT.RADIO);
		btnMicroSat.setText("Microsat");
		btnMicroSat.addSelectionListener(selectionSecteurListener);

		Label lblQuestion = new Label(container, SWT.NONE);
		lblQuestion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblQuestion.setText("Quelle liste de travail souhaitez vous ouvrir ?");

		comboTravail = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
		GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gridData.widthHint = 150;
		comboTravail.setLayoutData(gridData);

		return container;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, "Ok", true);
		createButton(parent, IDialogConstants.CANCEL_ID, "Annuler", false);
	}

	@Override
	protected Point getInitialSize() {
		return new Point(600, 300);
	}

	@Override
	protected void okPressed() {
		travail = comboTravail.getText();
		String resutlat = "";
		if (btnBM.getSelection()) {
			resutlat = btnBM.getText();
		}
		if (btnPrnatal.getSelection()) {
			resutlat = btnPrnatal.getText();
		}
		if (btnPucesPre.getSelection()) {
			resutlat = btnPucesPre.getText();
		}
		if (btnPostnatal.getSelection()) {
			resutlat = btnPostnatal.getText();
		}
		if (btnPucesPost.getSelection()) {
			resutlat = btnPucesPost.getText();
		}
		if (btnFoeto.getSelection()) {
			resutlat = btnFoeto.getText();
		}
		if (btnPucesFoeto.getSelection()) {
			resutlat = btnPucesFoeto.getText();
		}
		if (btnCaryo.getSelection()) {
			resutlat = btnCaryo.getText();
		}
		if (btnFishPuce.getSelection()) {
			resutlat = btnFishPuce.getText();
		}
		if (btnFishNonPuce.getSelection()) {
			resutlat = btnFishNonPuce.getText();
		}
		if (btnPuce.getSelection()) {
			resutlat = btnPuce.getText();
		}
		if (btnMicroSat.getSelection()) {
			resutlat = btnMicroSat.getText();
		}
		analyse = resutlat;
		super.okPressed();
	}

	public String getTravail() {
		return travail;
	}

	public String getAnalyse() {
		return analyse;
	}
}